<div class="alert-title">修改管理员账号信息</div>

<table class="user-info">
    <tr>
        <td class="title">用户名</td>
        <td class="field">
            <input type="text" class="am-form-field ui_uid" value="" placeholder="" disabled>
        </td>
        <td class="copy"></td>
    </tr>
    <tr>
        <td class="title">状态</td>
        <td class="field ui_state">
            <label class="am-radio-inline">
                <input type="radio" name="state" value="0" data-am-ucheck> 正常
            </label>
            <label class="am-radio-inline">
                <input type="radio" name="state" value="1" data-am-ucheck> 冻结
            </label>
            <label class="am-radio-inline">
                <input type="radio" name="state" value="2" data-am-ucheck> 停用
            </label>
        </td>
        <td class="copy"></td>
    </tr>

    <tr>
        <td class="title">真实姓名</td>
        <td class="field">
            <input type="text" class="am-form-field ui_name" value="" placeholder="请输入用户的真实姓名">
        </td>
        <td class="copy"></td>
    </tr>

    <tr>
        <td class="title">用户组</td>
        <td class="field">
            <select data-am-selected class="ui_grade">
            </select>
        </td>
        <td class="copy"></td>
    </tr>

    <tr>
        <td class="title">登录密码</td>
        <td class="field login-password">
            <input type="password" class="am-form-field" name="login-password" placeholder="留空为不修改"/>
        </td>
        <td class="copy"></td>
    </tr>

    <tr>
        <td class="title">QQ</td>
        <td class="field">
            <input type="number" class="am-form-field ui_qq" value="" placeholder="请输入用户的QQ">
        </td>
        <td class="copy"></td>
    </tr>

    <tr>
        <td class="title">微信</td>
        <td class="field">
            <input type="text" class="am-form-field ui_wechat" value="" placeholder="请输入用户的微信账号">
        </td>
        <td class="copy"></td>
    </tr>

    <tr>
        <td class="title">手机号</td>
        <td class="field">
            <input type="number" class="am-form-field ui_phone" value="" placeholder="请输入用户的手机号">
        </td>
        <td class="copy"></td>
    </tr>
</table>

<div class="button_line">
    <button class="btn-save admin_button">保存</button>
    <button class="close admin_button">关闭</button>
</div>
<style type="text/css">
    .user-info .title {
        width: 110px !important;
    }
</style>

<script>
    // 填充用户信息
    var u = context.center.user;
    $(".ui_uid").val(u.mobile);
    $(".ui_name").val(u.name || '');
    $(".ui_qq").val(u.qq || '');
    $(".ui_wechat").val(u.wechat || '');
    $(".ui_phone").val(u.phone || '');
    if (u.state == 0) {
        $(".ui_state input[value='0']").uCheck('check');
        $(".ui_state input[value='1']").uCheck('uncheck');
        $(".ui_state input[value='2']").uCheck('uncheck');
    }
    else if (u.state == 1) {
        $(".ui_state input[value='1']").uCheck('check');
        $(".ui_state input[value='0']").uCheck('uncheck');
        $(".ui_state input[value='2']").uCheck('uncheck');
    }
    else {
        $(".ui_state input[value='2']").uCheck('check');
        $(".ui_state input[value='0']").uCheck('uncheck');
        $(".ui_state input[value='1']").uCheck('uncheck');
    }
    
    // 用户组
    for (var i = 50; i < 99; i++) {
        var d = Rights.roles[i + ''];
        if (!d) continue;
        $(".ui_grade").append('<option value="' + i + '">' + d + '</option>');
    }
    $(".ui_grade").val(u.grade);

    $(".button_line .close").click(function() {
        $("#modify_admin_account").remove();
    });

    $(".button_line .btn-save").click(function() {
        var arr = [];

        // 是否有修改登录密码
        var v = $(".user-info input[name='login-password']").val().trim();
        if (v && !confirm("是否将用户的登录密码修改为：" + v + "？")) return;
        if (v) {
            arr.push(function(cb) {
                CMD.reset_password(u.id, $(".user-info input[name='login-password']").val().trim(), cb);
            });
        }

        // 用户组
        var v = $(".user-info .ui_grade").val();
        if (v != ui.grade) {
            arr.push(function(cb) {
                CMD.user_grade(u.id, $(".user-info .ui_grade").val(), cb);
            })
        }

        // 冻结/解冻账号
        var v = $(".ui_state input:checked").val();
        if (v != u.state) {
            arr.push(function(cb) {
                CMD.user_state(u.id, $(".ui_state input:checked").val(), cb);
            })
        }

        // 其他信息
        var data = {};
        var v = $(".user-info .ui_name").val().trim();
        if (v != u.name) data.name = v;
        var v = $(".user-info .ui_qq").val().trim();
        if (v != u.qq) data.qq = v;
        var v = $(".user-info .ui_wechat").val().trim();
        if (v != u.wechat) data.wechat = v;
        var v = $(".user-info .ui_phone").val().trim();
        if (v != u.phone) data.phone = v;

        // 保存信息
        if (!Util.isEmpty(data)) {
            arr.push(function(cb) {
                CMD.modify_user_info(u.id, data, cb);
            });
        }

        startLoading();
        Util.multiFuncs(arr, function() {
            stopLoading();
            $("#modify_admin_account").remove();
            alert2("信息保存完毕！");
            _f();
        });
    });
</script>